package com.briup.ch12;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/20
 * @Description:
 */
import java.io.*;
import java.net.*;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 8989);
        System.out.println("连接服务器，输入消息（quit退出）");

        try (
                BufferedReader in = new BufferedReader(
                        new InputStreamReader(socket.getInputStream()));
                PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
                Scanner sc = new Scanner(System.in)
        ) {
            String msg;
            while ((msg = sc.nextLine()) != null) {
                out.println(msg);
                if (msg.equalsIgnoreCase("quit")) break;
                System.out.println("服务器返回：" + in.readLine());
            }
        }
        System.out.println("退出");
    }
}